home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
nroff~06.zoo
/
command.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-17
|
37KB
|
1,970 lines
static char *rcsid_command_c="$Id: command.c,v 1.2 1992/07/16 10:38:32 rosenkra Exp $";
/*
* $Log: command.c,v $
* Revision 1.2 1992/07/16 10:38:32 rosenkra
* port to gcc, add tm,ie,el
*
*/
/*
* command.c - command input parser/processor for nroff text processor
*
* adapted for atariST/TOS by Bill Rosenkranz 11/89
* net: rosenkra@convex.com
* CIS: 71460,17
* GENIE: W.ROSENKRANZ
*
* original author:
*
* Stephen L. Browning
* 5723 North Parker Avenue
* Indianapolis, Indiana 46220
*
* history:
*
* - Originally written in BDS C;
* - Adapted for standard C by W. N. Paul
* - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
*/
#undef NRO_MAIN /* extern globals */
#include <stdio.h>
#include "nroff.h"
#define iscond(x) ((x)=='>'||(x)=='<'||(x)=='=')
#define isoper(x) ((x)=='+'||(x)=='-'||(x)=='*'||(x)=='/'||(x)=='%')
#define MAXCLEV 10
/* these must be globals: */
static int take_else[MAXCLEV+1]; /* for ie/el. T -> take el */
static int do_if[MAXCLEV+1]; /* flag if condition is T */
static int not_cond[MAXCLEV+1]; /* flag if !condition */
static int clev = 0; /* comand() is recursive. */
/* this is current level */
/*------------------------------*/
/* comand */
/*------------------------------*/
void comand (p)
REGISTER char *p;
{
/*
* main command processor
*/
REGISTER int i;
REGISTER int ct;
REGISTER int val;
REGISTER int indx;
int spval;
char argtyp;
char name[MAXLINE];
char macexp[MXMLEN];
char slenstr[MXMLEN];
int slen;
int tmp;
char *pfs;
char fs[20];
char c;
char *ps1;
char *ps2;
int sv_escon;
char wrdbuf[MAXLINE];
if (debugging)
fprintf (dbg_stream,
"***%s.comand: enter, clev=%d, p=|%s|\n",myname,clev+1,p);
/*
* if ". xx", skip blanks
*/
if (*(p+1) == ' ' || *(p+1) == '\t')
{
p = skipbl (++p);
*--p = dc.cmdchr;
}
/*
* get command code
*/
ct = comtyp (p, macexp);
/*
* error?
*/
if (ct == UNKNOWN)
{
fprintf (err_stream,
"***%s: unrecognized command %s\n", myname, p);
return;
}
/*
* ignore comments
*/
if (ct == COMMENT)
{
return;
}
/*
* bump command level (keep track of recursion). remember to dec
* when this routine returns. so far we only need this for ie/el
* processing since we need to track the state of the .ie condition.
*/
clev++;
/*
* do escape expansion on command line args
*/
expesc (p, name);
/*
* get value of command
*/
/* val = getval (p, &argtyp);*/
/*
* do the command
*/
switch (ct)
{
/* set (¶m, val, type, defval, minval, maxval) */
case FC:
/*
* field delim/pad chars
*
* .fc [delim] [pad]
*/
fprintf (err_stream, "***%s: .fc not available\n", myname);
break;
case TR:
/*
* translate
*
* .tr ab...
*/
fprintf (err_stream, "***%s: .tr not available\n", myname);
break;
/*NEW @ 1.2.0 */
case HY:
/*
* hyphenate
*
* .hy code
*
* for now code is really ignored unless 0 or 1.
*/
val = getval (p, &argtyp);
hyphenating = val;
break;
case NH:
/*
* not hyphenate
*
* .nh
*/
hyphenating = 0;
break;
case HC:
/*
* hyphenate char
*
* .hc c
*/
val = getval (p, &argtyp);
if (argtyp == '\r' || argtyp == '\n')
hyph_char = '%';
else
hyph_char = argtyp;
break;
case HW:
/*
* hyphenate words (IGNORED)
*
* .hw list
*/
break;
case TM:
/*
* terminal message
*
* .tm string
*/
val = getval (p, &argtyp);
p = skipwd (p);
p = skipbl (p);
/*
* force escape parsing, saving old setting
*/
sv_escon = dc.escon;
dc.escon = YES;
/*
* expand escape sequences
*/
expesc (p, wrdbuf);
/*
* print it (to stderr, has \n already)...
*/
fprintf (stderr, "%s", wrdbuf);
/*
* reset escape sequence processing
*/
dc.escon = sv_escon;
break;
case AD:
/*
* adjust
*
* .ad [mode]
*/
val = getval (p, &argtyp);
p = skipwd (p);
p = skipbl (p);
switch (*p)
{
case 'l':
dc.adjval = ADJ_LEFT;
dc.juval = YES;
break;
case 'r':
dc.adjval = ADJ_RIGHT;
dc.juval = YES;
break;
case 'c':
dc.adjval = ADJ_CENTER;
dc.juval = YES;
break;
case 'b':
case 'n':
dc.adjval = ADJ_BOTH;
dc.juval = YES;
break;
default:
break;
}
break;
case AF:
/*
* assign format to number reg
*
* .af R {1,a,A,i,I,0...1}
*/
val = getval (p, &argtyp);
p = skipwd (p);
p = skipbl (p);
if (!isalpha (*p))
{
fprintf (err_stream,
"***%s: invalid or missing number register name\n",
myname);
}
else
{
/*
* number register format is 1,a,A,i,I,0...1
* default is 1. for 0001 format, store num dig
* or'ed with 0x80, up to 8 digits.
*/
indx = tolower (*p) - 'a';
p = skipwd (p);
p = skipbl (p);
if (*p == '1')
dc.nrfmt[indx] = '1';
else if (*p == 'a')
dc.nrfmt[indx] = 'a';
else if (*p == 'A')
dc.nrfmt[indx] = 'A';
else if (*p == 'i')
dc.nrfmt[indx] = 'i';
else if (*p == 'I')
dc.nrfmt[indx] = 'I';
else if (*p == '0')
{
for (i = 0; isdigit (p[i]); i++)
;
dc.nrfmt[indx] = (char) (i);
if (dc.nrfmt[indx] <= 0)
dc.nrfmt[indx] = '1';
else if (dc.nrfmt[indx] > 8)
{
dc.nrfmt[indx] = 8;
dc.nrfmt[indx] |= 0x80;
}
else
dc.nrfmt[indx] |= 0x80;
}
else
dc.nrfmt[indx] = '1';
}
break;
case BD:
/*
* embolden font (IGNORED)
*
* .bd [S] F N
*/
break;
case BO:
/*
* bold face
*
* .bo [N]
*/
val = getval (p, &argtyp);
set (&dc.boval, val, argtyp, 1, 0, HUGE);
dc.cuval = dc.ulval = 0;
break;
case BP:
/*
* begin page
*
* .bp [+/-N]
*/
val = getval (p, &argtyp);
if (pg.lineno > 0)
space (HUGE);
set (&pg.curpag, val, argtyp, pg.curpag + 1, -HUGE, HUGE);
pg.newpag = pg.curpag;
set_ireg ("%", pg.newpag, 0);
break;
case BR:
/*
* break (page)
*
* .br
*/
robrk ();
break;
case BS:
/*
* backspc in output
*
* .bs [N]
*/
val = getval (p, &argtyp);
set (&dc.bsflg, val, argtyp, 1, 0, 1);
break;
case C2:
/*
* nobreak char
*
* .c2 [c=']
*/
val = getval (p, &argtyp);
if (argtyp == '\r' || argtyp == '\n')
dc.nobrchr = '\'';
else
dc.nobrchr = argtyp;
break;
case CC:
/*
* command character
*
* .cc [c=.]
*/
val = getval (p, &argtyp);
if (argtyp == '\r' || argtyp == '\n')
dc.cmdchr = '.';
else
dc.cmdchr = argtyp;
break;
case CE:
/*
* center
*
* .ce [N]
*/
val = getval (p, &argtyp);
robrk ();
set (&dc.ceval, val, argtyp, 1, 0, HUGE);
break;
case CS:
/*
* constant space char (IGNORED)
*
* .cs F N M
*/
break;
case CU:
/*
* continuous underline
*
* .cu [N]
*/
val = getval (p, &argtyp);
set (&dc.cuval, val, argtyp, 1, 0, HUGE);
dc.ulval = dc.boval = 0;
break;
case DE:
/*
* define macro
*
* .de name [end]
*/
val = getval (p, &argtyp);
ignoring = FALSE;
defmac (p, sofile[dc.flevel]);
break;
case DS:
/*
* define string
*
* .ds name string
*/
val = getval (p, &argtyp);
defstr (p);
break;
case EC:
/*
* escape char
*
* .ec [c=\]
*/
val = getval (p, &argtyp);
if (argtyp == '\r' || argtyp == '\n')
dc.escchr = '\\';
else
dc.escchr = argtyp;
dc.escon = YES;
break;
case EF:
/*
* even footer
*
* .ef "a" "b" "c"
*/
val = getval (p, &argtyp);
gettl (p, pg.efoot, &pg.eflim[0]);
break